<template>
  <div class="my-order" ref="container" style="top: 0; bottom: 0;">
    <scroller
      :on-infinite="infinite"
      :on-refresh="refresh"
      　　
      ref="my_scroller"
    >
      <div class="list">
        <div
          class="item"
          v-for="order in orderList"
          :key="order.id"
          style="position:relative;"
        >
          <div class="title acea-row row-between-wrapper">
            <div class="acea-row row-middle">
              <img src="@assets/images/shopgery.png" alt="" srcset="" />
              {{ order.cartInfo[0].merchant_name }}
            </div>
            <div class="font-color-red">{{ getStatus(order) }}</div>
          </div>
          <div
            @click="toDetailPage(order)"
            class="goodWrapper"
            style="padding:0.32rem 0 0.24rem 0;"
          >
            <div
              class="item acea-row row-between-wrapper"
              v-for="cart in order.cartInfo"
              :key="cart.id"
              style="padding-top:0;padding-bottom:0;"
            >
              <div class="pictrue">
                <img
                  class="image"
                  :src="cart.productInfo.image"
                  @click.stop="
                    $router.push({
                      path:
                        '/detail/' +
                        cart.productInfo.id +
                        '?mer_id=' +
                        order.mer_id
                    })
                  "
                  v-if="cart.combination_id === 0 && cart.bargain_id === 0"
                />
                <img
                  class="image"
                  :src="cart.productInfo.image"
                  @click.stop="
                    $router.push({
                      path: '/activity/group_detail/' + cart.combination_id
                    })
                  "
                  v-else-if="cart.combination_id > 0"
                />
                <img
                  class="image"
                  :src="cart.productInfo.image"
                  @click.stop="
                    $router.push({
                      path: '/activity/dargain_detail/' + cart.bargain_id
                    })
                  "
                  v-else-if="cart.bargain_id > 0"
                />
                <!-- <img
                  class="image"
                  :src="cart.productInfo.image"
                   @click.stop="
                    $router.push({ path: '/detail/' + cart.productInfo.id+'?mer_id='+order.mer_id })
                  "
                  v-else-if="cart.seckill_id > 0"
                /> -->
              </div>
              <div class="text">
                <div class="acea-row row-between-wrapper">
                  <div class="name line1">
                    {{ cart.productInfo.store_name }}
                  </div>
                  <!-- <div class="num">x {{ cart.cart_num }}</div> -->
                </div>
                <div class="attr line1" v-if="cart.productInfo.attrInfo">
                  {{ cart.productInfo.attrInfo.suk }}
                </div>
                <div class="money font-color-red">
                  <template v-if="order.is_virtual == 0">
                    <span
                      v-show="cart.productInfo.is_seven_returned == 1"
                      class="cantui"
                      >7天无理由退换货</span
                    >
                    <span
                      v-show="cart.productInfo.is_seven_returned == 0"
                      class="cantui"
                      >不支持7天无理由退货</span
                    >
                  </template>
                  <span v-else class="cantui">虚拟商品</span>
                </div>
                <div
                  class="evaluate"
                  v-if="evaluate === 3"
                  @click="
                    $router.push({ path: '/goods_evaluate/' + cart.unique })
                  "
                >
                  评价
                </div>
              </div>
            </div>
          </div>
          <div class="totalPrice">
            <span class="all">共{{ order.orderNum }}件商品</span>
            <span class="coupon_money">优惠{{ order.coupon_price }}元</span>
            <span class="money">￥{{ order.pay_price }}</span>
            <span class="heji">合计</span>
          </div>
          <div
            class="refund_msg"
            v-if="order.sale_status == '1' && order.refund_name != ''"
          >
            <p class="refund_title">退货信息</p>
            <div class="refund_name_phone">
              <p class="refund_name">退货联系人：{{ order.refund_name }}</p>
              <p class="refund_phone">联系方式：{{ order.refund_phone }}</p>
            </div>
            <div class="refund_address_new">
              <p class="address_title">退货地址：</p>
              <p class="address_comtent">{{ order.refund_address }}</p>
            </div>
          </div>
          <div
            class="refund_msg"
            v-if="
              order.sale_status == '2' ||
                order.sale_status == '4' ||
                (order.sale_status == '5' && order.sale_remark != '')
            "
          >
            <p class="refund_title">商家反馈</p>
            <div class="refund_name_phone" style="padding-bottom:0.2rem;">
              {{ order.sale_remark }}
            </div>
          </div>
          <div
            class="refund_msg_alert"
            v-if="order.sale_status == '1' && order.apply_name == ''"
          >
            请退货后上传您的物流单号，否则将会影响您的退款进度
          </div>
          <div class="wu_number" v-if="order.apply_name != ''">
            <p>退货物流: {{ order.apply_name }}</p>
            <p>物流单号: {{ order.apply_poster_num }}</p>
          </div>

          <!-- 退货地址 -->
          <!-- <div class="refund_address" v-if="order.refund_address">
            <span>退货信息</span>
            <div>{{ order.refund_address }}</div>
          </div> -->
          <div class="bottom acea-row row-right row-middle">
            <!-- 未付款 -->
            <template v-if="order.listStatus == '0'">
              <!-- <div class="bnt cancelBnt" @click="cancelOrder(order)">
                取消订单
              </div>
              <div v-if="order.isMergeSub == '2' " class="bnt bg-color-red" @click="paymentTap(order)">
              </div> -->
              <div
                v-if="order.isMergeSub == '2'"
                class="bnt bg-color-red"
                @click="paymentTap(order)"
              >
                付款
              </div>
              <div
                v-if="order.isMergeSub == '1'"
                class="bnt bg-color-red"
                @click="paymentTap(order)"
              >
                合并付款
              </div>
            </template>
            <!-- 未发货 -->
            <template v-if="order.listStatus == '1'">
              <div
                v-if="
                  order.sale_status != '0' &&
                    order.sale_status != '1' &&
                    order.sale_status != '2' &&
                    order.sale_status != '3' &&
                    order.sale_status != '4' &&
                    order.sale_status != '5'
                "
                class="bnt cancelBnt"
                @click="drawback(order)"
              >
                退款
              </div>
              <div
                v-if="order.sale_status == '1'"
                class="bnt cancelBnt"
                @click="toBooking(order.order_id)"
                style="width:2.2rem;"
              >
                填写退货物流单号
              </div>
              <div
                class="bnt cancelBnt"
                @click="
                  $router.push({
                    path:
                      '/user/add_address/' +
                      order.order_id +
                      '?type=-2&orderId=' +
                      order.id
                  })
                "
              >
                更换地址
              </div>
            </template>
            <!-- 待发货 -->
            <template v-if="order.listStatus == '2'">
              <div
                class="bnt cancelBnt"
                @click="
                  $router.push({ path: '/order/logistics/' + order.order_id })
                "
              >
                查看物流
              </div>
              <div class="bnt bg-color-red" @click="takeOrder(order)">
                确认收货
              </div>
            </template>
            <!-- 交易完成 -->
            <template v-if="order.listStatus == '3'">
              <div
                v-if="
                  order.cartInfo[0].productInfo.is_seven_returned == 1 &&
                    order.sale_status != '0' &&
                    order.sale_status != '1' &&
                    order.sale_status != '2' &&
                    order.sale_status != '3' &&
                    order.sale_status != '4' &&
                    order.sale_status != '5'
                "
                class="bnt cancelBnt"
                @click="drawback(order)"
              >
                退款
              </div>
              <div
                v-if="order.sale_status == '1'"
                class="bnt cancelBnt"
                @click="toBooking(order.order_id)"
                style="width:2.2rem;"
              >
                填写退货物流单号
              </div>
              <div
                class="bnt cancelBnt"
                @click="
                  $router.push({ path: '/order/logistics/' + order.order_id })
                "
              >
                查看物流
              </div>
            </template>
            <!-- 退款 -->
            <template v-if="order.listStatus == '4'">
              <div
                v-if="order.is_virtual == 1 && order.paid == 1"
                class="bnt cancelBnt"
                @click="toCodeDetail(order.order_id)"
              >
                查看兑换码
              </div>
              <div
                v-if="order.sale_status == '1'"
                class="bnt cancelBnt"
                @click="toBooking(order.order_id)"
                style="width:2.2rem;"
              >
                填写退货物流单号
              </div>
              <!-- <span class="refund_addresstxt" v-if="order.refund_address">请按照上述退货地址退货</span> -->
              <div class="bnt cancelBnt" @click="telshow(order.service_tel)">
                联系客服
              </div>
            </template>
          </div>
        </div>
      </div>
    </scroller>
    <div
      class="noCart"
      v-if="orderList.length === 0 && page >= 1 && canSCroll == true"
    >
      <div class="pictrue"><img src="@assets/images/noOrder.png" /></div>
      <p class="txt">暂无订单信息</p>
    </div>
    <Payment
      v-model="pay"
      :types="payType"
      @checked="toPay"
      :balance="userInfo.now_money"
    ></Payment>
    <GeneralWindow
      :generalActive="generalActive"
      @closeGeneralWindow="closeGeneralWindow"
      :generalContent="generalContent"
    ></GeneralWindow>
    <!-- 客服弹窗 -->
    <div class="telbox" @click="telhide" v-show="telShow == '1'">
      <div class="tel">
        <p class="telTitle">客服电话 {{ service_tel }}</p>
        <p class="telTime">工作日时间:周一至周五9:00-18:00</p>
        <p class="line"></p>
        <a :href="'tel:' + this.service_tel"
          ><p class="telSend">拨打客服电话</p></a
        >
      </div>
    </div>
    <!-- 下载 -->
    <div class="toastDownload" v-show="showdownlod == '1'" @click="quxiao()">
      <div class="modela">
        <p>请下载听见广播APP进行退款操作</p>
        <div>
          <span class="quxiao" @click.stop="quxiao()">取消</span>
          <span class="sure" @click.stop="downLoad()">去下载</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getOrderData, getOrderList } from "@api/order";
import {
  cancelOrderHandle,
  payOrderHandle,
  takeOrderHandle
} from "@libs/order";
import Loading from "@components/Loading";
import Payment from "@components/Payment";
import cookie from "@utils/store/cookie";
import { clearAuthStatus } from "@libs/wechat";
import { mapGetters } from "vuex";
import { isWeixin } from "@utils";
import GeneralWindow from "@components/GeneralWindow";
import dayjs from "dayjs";
import { connect } from "net";
import { setInterval, clearInterval } from "timers";

const STATUS = [
  "等待付款",
  "等待商家发货",
  "等待收货",
  "待评价",
  "已完成",
  "",
  "",
  "",
  "",
  "待付款"
];

const NAME = "MyOrder";

export default {
  name: NAME,
  data() {
    return {
      telShow: "0",
      offlinePayStatus: 2,
      orderData: {},
      type: "",
      page: 1,
      limit: 20,
      loaded: false,
      loading: false,
      orderList: [],
      pay: false,
      payType: ["yue", "weixin"],
      from: "",
      active: "",
      generalActive: false,
      generalContent: {
        promoterNum: "",
        title: ""
      },
      from1: "",
      noDate: false, //重置数据判断
      canSCroll: false,
      service_tel: "",
      orderId: "",
      showdownlod: "",
      downloadmsg: "",
      btn: ""
    };
  },
  components: {
    Loading,
    Payment,
    GeneralWindow
  },
  computed: mapGetters(["userInfo"]),
  watch: {
    $route(n) {
      if (n.name === NAME) {
        const type = parseInt(this.$route.params.type) || 0;
        if (this.type !== type) {
          this.changeType(type);
        }
        this.getOrderData();
      }
    }
  },

  methods: {
    // 去详情页
    toDetailPage(order){
      if(order.is_new_bargain == '0'){
        this.$router.push({ path:`/order/detail/${order.order_id}?mer_id=${order.mer_id}`})
      }else{
        this.$router.push({ path:`/cutPrice/cutPriceDetails?order_id=${order.order_id}&pageFrom=orderList&from1=${this.from1}`})
      }
    },
    // 去兑换码页面
    toCodeDetail(id) {
      this.$router.push(`/user/user_exchangecode?id=${id}`);
    },
    //填写物流信息
    toBooking: function(id) {
      console.log(id);
      this.$router.push({ path: "/order/bookingNote?uni=" + id });
    },
    downLoad: function() {
      var self = this;

      if (this.btn == "登录") {
        console.log(this.loginurl);
        setTimeout(() => {
          self.$router.push({ path: self.loginurl });
        }, 1000);
      } else if (self.downloadmsg == "您的播豆不足，是否现在购买?") {
        this.showdownlod = "";
        self.sureBuy();
      } else if (self.btn == "重新登录") {
        self.$router.push({
          path: "./change?channel_id=" + self.cbct.getCookie("channel_id")
        });
      } else {
        var u = navigator.userAgent,
          app = navigator.appVersion;
        var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

        if (isAndroid) {
          var ua = navigator.userAgent.split("(")[1].split(")")[0];
          // alert(ua);
          var phone = [
            /IPHONE/gi,
            /huawei/gi,
            /mi/gi,
            /vivo/gi,
            /OPPO/gi,
            /samsung/gi,
            /SONY/gi,
            /Nokia/gi,
            /HTC/gi,
            /ZTE/gi,
            /Lenovo/gi,
            /ZUK/gi
          ];
          if (phone[1].test(ua)) {
            window.location.href =
              "https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C100594819?source=appshare&subsource=C100594819";
          } else if (phone[2].test(ua)) {
            window.location.href = "http://app.xiaomi.com/detail/760715";
          } else if (phone[3].test(ua)) {
            window.location.href =
              "http://appdetailh5.vivo.com.cn/detail/2418329?source=7";
          } else if (phone[4].test(ua)) {
            window.location.href =
              "http://appdetailh5.vivo.com.cn/detail/2418329?source=7";
          } else {
            var uas = navigator.userAgent.toLowerCase();
            if (uas.match(/MicroMessenger/i) == "micromessenger") {
              window.location.href =
                "https://sj.qq.com/myapp/detail.htm?apkName=cn.cbct.seefm";
            } else {
              window.location.href =
                "https://sj.qq.com/myapp/detail.htm?apkName=cn.cbct.seefm";
            }
          }
        }
        if (isIOS) {
          window.location.href =
            "https://itunes.apple.com/cn/app/%E5%90%AC%E8%A7%81%E5%B9%BF%E6%92%AD-%E5%8F%AF%E5%90%AC%E5%8F%AF%E7%9C%8B%E7%9A%84%E5%B9%BF%E6%92%AD%E7%94%B5%E5%8F%B0%E8%8A%82%E7%9B%AE%E7%9B%B4%E6%92%AD/id1439524045?mt=8";
        }
      }
    },
    quxiao: function() {
      this.showdownlod = "";
    },
    //声音禁掉
    isNo: function() {
      var u = navigator.userAgent,
        app = navigator.appVersion;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      const win = window;
      var obj = {
        action: "onClickPlay",
        content: {}
      };
      if (isAndroid) {
        App.onAppResponse(JSON.stringify(obj));
      }
      if (isIOS) {
        win.webkit.messageHandlers.onAppResponse.postMessage(
          JSON.stringify(obj)
        );
      }
    },
    telshow(tel) {
      if (tel == null || tel.length == 0 || tel == undefined) {
        return this.$dialog.toast({ mes: "系统正在维护中" });
      } else {
        (this.telShow = "1"), (this.service_tel = tel);
      }
    },
    telhide() {
      this.telShow = "0";
    },
    getParameter: function() {
      var self = this;
      var u = navigator.userAgent,
        app = navigator.appVersion;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      const win = window;
      var obj = {
        action: "getParameter",
        content: {
          method: "setUserInfo",
          Parameter: {}
        }
      };
      if (isAndroid) {
        App.onAppResponse(JSON.stringify(obj));
      }
      if (isIOS) {
        win.webkit.messageHandlers.onAppResponse.postMessage(
          JSON.stringify(obj)
        );
      }
    },
    infinite(done) {
      var self = this;
      setTimeout(function() {
        console.log(self.noDate);
        var timer1 = setInterval(function() {
          if (!self.canSCroll) {
          } else {
            if (self.noDate) {
              if (self.page == "1") {
                self.$refs.my_scroller.finishInfinite(2);
              } else {
                self.$refs.my_scroller.finishInfinite(2); //这个方法是不让它加载了，显示“没有更多数据”，要不然会一直转圈圈
              }
            } else {
              setTimeout(() => {
                self.page++; //下拉一次页数+1
                console.log(self.page);
                self.getOrderList();
                done(); //进行下一次加载操作
              }, 500);
            }
            clearInterval(timer1);
          }
        }, 100);
      }, 200);
    },
    refresh() {
      var self = this;
      var timer2 = setInterval(function() {
        if (!self.canSCroll) {
          this.$refs.my_scroller.finishPullToRefresh();
        } else {
          self.page = 1; //重置页数刷新每次页数都是第一页
          self.noDate = false; //重置数据判断
          setTimeout(
            function() {
              self.getOrderList();
              self.$refs.my_scroller.finishPullToRefresh(); //刷新完毕关闭刷新的转圈圈
            }.bind(this),
            700
          );
          clearInterval(timer2);
        }
      }, 100);
    },
    // 嵌入app获取支付状态
    onWebResponse: function(str) {
      var obj = JSON.parse(str);
      var action = obj.action;
      var self = this;
      var content = obj.content;
      if (action == "payResult") {
        // alert(123);
        // alert(content.data.order_id);
        // alert("/order/status/"+this.orderId+"/2");
        if (content.status == "0") {
          // alert(content.data.order_id)
          this.$router.replace({
            path: "/order/status/" + content.data.order_id + "/2?from1=app"
          });
        } else if (content.status == "1") {
          // alert(content.data.order_id)
          // return this.$dialog.error("支付成功");
          this.$router.replace({
            path: "/order/status/" + content.data.order_id + "/2?from1=app"
          });
        }
      } else if (action == "setUserInfo") {
        let did = content.did;
        let isToken = content.ds_token;
        let expires_time = content.ds_expires_time;
        let isSalt = content.salt;
        if (isToken == "") {
          this.$store.commit(
            "LOGIN",
            isToken
            // dayjs(expires_time) - newTime
          );
        } else {
          let newTime = Math.round(new Date() / 1000);
          this.$store.commit(
            "LOGIN",
            isToken
            // dayjs(expires_time) - newTime
          );
        }
      }
    },
    setOfflinePayStatus: function(status) {
      var that = this;
      that.offlinePayStatus = status;
      if (status === 1) {
        if (that.payType.indexOf("offline") < 0) {
          that.payType.push("offline");
        }
      }
    },
    getOrderData() {
      getOrderData().then(res => {
        this.orderData = res.data;
      });
    },
    //ios微信支付做桥
    payTypes: function(data) {
      var u = navigator.userAgent,
        app = navigator.appVersion;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      const win = window;
      var obj = {
        action: "payBridge", //方法名
        content: {
          type: this.active, //微信 aliPay//支付宝
          data: data //支付信息
        }
      };
      if (isAndroid) {
        App.onAppResponse(JSON.stringify(obj));
      }
      if (isIOS) {
        win.webkit.messageHandlers.onAppResponse.postMessage(
          JSON.stringify(obj)
        );
      }
    },
    payTypeWxapp: function(data) {
      wx.miniProgram.navigateTo({
        url:
          "/pages/pay/pay?prepay_id=" +
          data.jsConfig.prepay_id +
          "&appid=" +
          data.jsConfig.appid +
          "&nonce_str=" +
          data.jsConfig.nonce_str +
          "&sign=" +
          data.jsConfig.sign +
          "&sign_type=" +
          data.jsConfig.sign_type +
          "&timeStamp=" +
          data.jsConfig.timeStamp +
          "&orderId=" +
          data.orderId
      });
    },
    takeOrder(order) {
      this.$dialog.loading.open("正在加载中");
      takeOrderHandle(order.order_id)
        .then(res => {
          if (
            (res.data.gain_integral != "0.00" &&
              res.data.gain_coupon != "0.00") ||
            (res.data.gain_integral > 0 && res.data.gain_coupon > 0)
          ) {
            this.$dialog.loading.close();
            this.generalActive = true;
            this.generalContent = {
              promoterNum: `恭喜您获得${res.data.gain_coupon}元优惠券以及${res.data.gain_integral}积分，购买商品时可抵现哦～`,
              title: "恭喜您获得优惠礼包"
            };
            return;
          } else if (
            res.data.gain_integral != "0.00" ||
            res.data.gain_integral > 0
          ) {
            this.$dialog.loading.close();
            this.generalActive = true;
            this.generalContent = {
              promoterNum: `恭喜您获得${res.data.gain_integral}积分，购买商品时可抵现哦～`,
              title: "赠送积分"
            };
            return;
          } else if (
            res.data.gain_coupon != "0.00" ||
            res.data.gain_coupon > 0
          ) {
            this.$dialog.loading.close();
            this.generalActive = true;
            this.generalContent = {
              promoterNum: `恭喜您获得${res.data.gain_coupon}元优惠券，购买商品时可抵现哦～`,
              title: "恭喜您获得优惠券"
            };
            return;
          } else {
            this.$dialog.loading.close();
            this.$dialog.success("收货成功");
          }
          this.getOrderData();
          this.orderList = [];
          this.page = 1;
          this.loaded = false;
          this.loading = false;
          this.getOrderList();
        })
        .catch(err => {
          this.$dialog.loading.close();
          this.$dialog.error(err.msg);
        });
    },
    closeGeneralWindow(msg) {
      this.generalActive = msg;
      this.reload();
      this.getOrderData();
    },
    reload() {
      this.changeType(this.type);
    },
    changeType(type) {
      this.type = type;
      this.orderList = [];
      this.page = 1;
      this.loaded = false;
      this.loading = false;
      this.getOrderList();
    },
    getOrderList() {
      var that = this;
      // if (this.loading || this.loaded) return;
      // this.loading = true;
      const { page, limit, type } = this;
      getOrderList({
        page,
        limit,
        type
      }).then(res => {
        that.$refs.my_scroller.finishPullToRefresh();
        let d = res.data;
        var length = 0;
        if (d.length == length) {
          that.noDate = true;
          if (that.page == 1) {
            that.canSCroll = true;
            // that.$refs.my_scroller.finishPullToRefresh();//刷新完毕关闭刷新的转圈圈
          }
        } else if (that.page == 1) {
          this.canSCroll = true;
          this.orderList = res.data;
        } else {
          that.orderList = that.orderList.concat(res.data);
        }
        for (var i = 0; i < that.orderList.length; i++) {
          var orderNum = 0;
          for (var j = 0; j < that.orderList[i].cartInfo.length; j++) {
            orderNum += that.orderList[i].cartInfo[j].cart_num;
          }
          that.$set(that.orderList[i], "orderNum", orderNum);
        }
        console.log(that.orderList);
      });
    },
    getStatus(order) {
      // return STATUS[order._status._type];
      if (order.paid == "0") {
        this.$set(order, "listStatus", "0");
        return "等待付款";
      } else if (
        order.paid == "1" &&
        order.status == "0" &&
        order.refund_status == "0"
      ) {
        this.$set(order, "listStatus", "1");
        return "等待商家发货";
      } else if (
        order.paid == "1" &&
        order.status == "1" &&
        order.refund_status == "0"
      ) {
        this.$set(order, "listStatus", "2");
        return "等待收货";
      } else if (
        order.refund_status == "0" &&
        order.status == "3" &&
        order.is_system_del == "0"
      ) {
        this.$set(order, "listStatus", "3");
        return "交易完成";
      } else if (
        order.refund_status == "0" &&
        order.status == "2" &&
        order.is_system_del == "0"
      ) {
        this.$set(order, "listStatus", "4");
        return "交易完成";
      } else if (order.paid == "1" && order.refund_status == "1") {
        if (
          order.apply_name != "" &&
          order.sale_status != "4" &&
          order.sale_status != "5" &&
          order.sale_status != "3"
        ) {
          this.$set(order, "listStatus", "4");
          return "退款中";
        } else {
          if (order.sale_status == "0") {
            this.$set(order, "listStatus", "4");
            return "退款申请中";
          } else if (order.sale_status == "1") {
            this.$set(order, "listStatus", "4");
            return "审核通过，请退货";
          } else if (order.sale_status == "2") {
            this.$set(order, "listStatus", "4");
            return "审核未通过";
          } else if (order.sale_status == "3") {
            this.$set(order, "listStatus", "4");
            return "退款成功";
          } else if (order.sale_status == "4") {
            this.$set(order, "listStatus", "4");
            return "退款失败";
          } else if (order.sale_status == "5") {
            this.$set(order, "listStatus", "4");
            return "交易完成";
          } else {
            this.$set(order, "listStatus", "4");
            return "退款中";
          }
        }
      } else if (order.paid == "1" && order.refund_status == "2") {
        if (order.sale_status == "3") {
          this.$set(order, "listStatus", "4");
          return "退款成功";
        } else if (order.sale_status == "4") {
          this.$set(order, "listStatus", "4");
          return "退款失败";
        } else if (order.sale_status == "5") {
          this.$set(order, "listStatus", "4");
          return "交易完成";
        } else {
          this.$set(order, "listStatus", "4");
          return "退款成功";
        }
      } else if (order.is_system_del == "1") {
        this.$set(order, "listStatus", "4");
        return "交易完成,订单关闭";
      }
      console.log(this.order.listStatus);
    },
    drawback(order) {
      if (this.from1 == "app") {
        if (order.listStatus == "1") {
          this.$router.push({
            path:
              "/order/refund/" +
              order.order_id +
              "?is_diff=" +
              order.is_diff +
              "&name=" +
              order.real_name +
              "&phone=" +
              order.user_phone +
              "&pay_price=" +
              order.pay_price
          });
        } else {
          this.$router.push({
            path:
              "/order/refund/" +
              order.order_id +
              "?is_diff=" +
              order.is_diff +
              "&name=" +
              order.real_name +
              "&phone=" +
              order.user_phone +
              "&pay_price=" +
              order.pay_price
          });
        }
      } else {
        if (order.listStatus == "1") {
          this.$router.push({
            path:
              "/order/refund/" +
              order.order_id +
              "?is_diff=" +
              order.is_diff +
              "&name=" +
              order.real_name +
              "&phone=" +
              order.user_phone +
              "&pay_price=" +
              order.pay_price
          });
        } else {
          this.$router.push({
            path:
              "/order/refund/" +
              order.order_id +
              "?is_diff=" +
              order.is_diff +
              "&name=" +
              order.real_name +
              "&phone=" +
              order.user_phone +
              "&pay_price=" +
              order.pay_price
          });
        }
      }
    },
    cancelOrder(order) {
      cancelOrderHandle(order.order_id)
        .then(() => {
          this.getOrderData();
          this.orderList.splice(this.orderList.indexOf(order), 1);
        })
        .catch(() => {
          this.reload();
        });
    },
    // 下载
    gotodown: function(msg, btn1) {
      this.showdownlod = "1";
      this.downloadmsg = "请下载听见广播APP进行退款操作";
      this.btn = "去下载";
    },
    paymentTap: function(order) {
      console.log(order);
      var that = this;

      if (
        !(
          order.combination_id > 0 ||
          order.bargain_id > 0 ||
          order.seckill_id > 0
        )
      ) {
        that.setOfflinePayStatus(order.offlinePayStatus);
      }
      this.pay = true;
      this.toPay = type => {
        var isIOS1 = "";
        var u = navigator.userAgent,
          app = navigator.appVersion;
        var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isIOS) {
          isIOS1 = "ios";
        } else {
          isIOS1 = "qwe";
        }
        if (type == "aliPay") {
          if (this.from1 == "app") {
            this.from = "aliPayApp";
          } else {
            this.from = "aliPayH5";
          }
        } else if (type == "weChatPay") {
          if (this.from1 == "app") {
            this.from = "weChatPayApp";
          } else if (this.from1 == "wxapp") {
            this.from = "weChatPaywxApp";
          } else {
            this.from = isWeixin() ? "weChatPayH5" : "weChatPayPage";
          }
        }
        payOrderHandle(
          order.order_id,
          type,
          that.from,
          isIOS1,
          cookie.get("OID")
        )
          .then(res => {
            const type = parseInt(this.$route.params.type) || 0;
            that.changeType(type);
            that.getOrderData();
          })
          .catch(res => {
            console.log(res.data);
            const data = res.data;
            if (res.status === "WECHAT_PAY") {
              pay(data.result.jsConfig).finally(() => {
                this.$router.replace({
                  path: "/order/status/" + data.result.order_id
                });
              });
            }
            if (res.status === "WECHAT_APP_PAY") {
              this.payTypes(data.result);
            }
            if (res.status === "ALI_APP_PAY") {
              this.payTypes(data.result);
            }
            if (res.status === "WECHAT_WXAPP_PAY") {
              this.payTypeWxapp(data.result);
            }
            if (res.status === "ALI_H5_PAY") {
              setTimeout(() => {
                location.href = data.result.jsConfig;
              }, 1);
            }
            if (res.status === "WECHAT_H5_PAY") {
              // return that.$router.push({
              //   path: "/order/status/" + order.order_id + "/5"
              // });
              setTimeout(() => {
                location.href = data.result.jsConfig.mweb_url;
              }, 1);
            }
            const type = parseInt(that.$route.params.type) || 0;
            that.changeType(type);
            that.getOrderData();
          });
      };
    },
    toPay() {}
  },
  created() {
    if (this.$route.query.from1 == "app") {
      cookie.set("from1", "app");
    }
  },
  mounted() {
    var that = this;
    var self = this;
    if (this.$route.query.isToken) {
      this.$store.commit(
        "LOGIN",
        this.$route.query.isToken
        // dayjs(expires_time) - newTime
      );
      cookie.set("OID", this.$route.query.oId);
    }
    let isFromApp = this.$route.query.from1;
    this.from1 = isFromApp;
    console.log(this.from1);
    if (isFromApp == "app") {
      this.from1 = "app";
      // cookie.set("from1", "app");
      // if (cookie.get("from1") == "" || cookie.get("from1") == undefined) {
        
      // }
      this.isNo();
      this.getParameter();
      window["onWebResponse"] = str => {
        that.onWebResponse(str);
      };
      setTimeout(function() {
        self.getOrderData();
        self.getOrderList();
      }, 1000);
    } else if (isFromApp == "wxapp") {
      self.getOrderData();
      self.getOrderList();
    } else {
      self.getOrderData();
      self.getOrderList();
    }
    var u = navigator.userAgent,
      app = navigator.appVersion;
    var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  }
};
</script>
<style scoped>
.toastDownload {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 100;
}
.toastDownload .modela {
  position: absolute;
  width: 6.22rem;
  height: auto;
  margin-left: 0.64rem;
  top: 50%;
  transform: translateY(-1.26rem);
  background: #fff;
  font-size: 0.28rem;
  border-radius: 0.16rem;
}
.toastDownload .modela h1 {
  margin-top: 0.64rem;
  font-size: 0.34rem;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  padding: 0 0.48rem;
}
.toastDownload .modela p {
  color: rgba(0, 0, 0, 0.5);
  line-height: 1;
  text-align: center;
  font-size: 0.32rem;
  padding: 0 0.48rem;
  padding-top: 0.64rem;
}
.toastDownload .modela div {
  margin-top: 0.66rem;
  display: flex;
  height: 1.04rem;
  width: 100%;
  border-top: 0.01rem solid rgba(0, 0, 0, 0.2);
  font-family: PingFangSC-Medium, PingFang SC;
  letter-spacing: 0.1rem;
  text-align: center;
}
.toastDownload .modela div .quxiao {
  flex: 1;
  color: rgba(102, 102, 102, 0.5);
  border-right: 0.01rem solid rgba(0, 0, 0, 0.2);
  line-height: 1.04rem;
  font-size: 0.32rem;
  font-family: PingFangSC-Medium, PingFang SC;
}
.toastDownload .modela div .sure {
  flex: 1;
  color: rgba(68, 115, 225, 1);
  line-height: 1.04rem;
  font-size: 0.32rem;
  font-family: PingFangSC-Medium, PingFang SC;
}
.telbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 3, 3, 0.5);
  overflow: hidden;
}
.tel {
  width: 6rem;
  height: 3.7rem;
  background: rgba(255, 255, 255, 1);
  border-radius: 0.16rem;
  margin: 40% auto 0;
  box-sizing: border-box;
  text-align: center;
}
.telTitle {
  font-size: 0.34rem;
  color: #333;
  padding-top: 0.66rem;
}
.telTime {
  font-size: 0.32rem;
  color: rgba(0, 0, 0, 0.5);
  margin-top: 0.36rem;
}
.line {
  width: 100%;
  height: 0.01rem;
  margin: 0.68rem auto 0.3rem;
  background: rgba(0, 0, 0, 0.2);
}
.telSend {
  font-size: 0.32rem;
  color: #4473e1;
}
.zanwei {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 1rem;
  background: rgb(245, 245, 245);
}
.noCart {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 99;
  background: rgb(245, 245, 245);
}

.noCart .pictrue {
  width: 4rem;
  height: 3rem;
  margin: 46% auto 0.5rem auto;
}

.noCart .pictrue img {
  width: 100%;
  height: 100%;
}
.noCart .txt {
  font-size: 0.24rem;
  color: rgba(0, 0, 0, 0.4);
  text-align: center;
  letter-spacing: 0.01rem;
}
/* 退货地址 */
.refund_address {
  width: 6.9rem;
  height: auto;
  padding: 0.14rem 0;
  background: rgba(50, 64, 77, 0.04);
  margin: 0 auto 0.3rem;
  box-sizing: border-box;
  display: flex;
}
.refund_address span {
  display: inline-block;
  margin: 0 0.2rem 0 0.14rem;
  font-size: 0.24rem;
  color: rgba(0, 0, 0, 0.5);
  word-break: keep-all;
}
.refund_address div {
  word-wrap: break-word;
  word-break: normal;
  font-size: 0.24rem;
  font-weight: 400;
  line-height: 0.34rem;
  color: rgba(0, 0, 0, 0.8);
}
.refund_addresstxt {
  font-size: 0.24rem;
  font-weight: 400;
  color: rgba(255, 35, 35, 0.79);
  position: absolute;
  left: 0.3rem;
}
.refund_msg {
  width: 6.9rem;
  margin: 0.3rem;
  background: rgba(247, 247, 247, 1);
  height: auto;
  border-radius: 0.16rem;
}
.refund_msg .refund_title {
  color: rgba(0, 0, 0, 1);
  font-size: 0.24rem;
  padding: 0.24rem 0.24rem 0.14rem 0.24rem;
  line-height: 0.34rem;
}
.refund_msg .refund_name_phone {
  display: flex;
  justify-content: flex-start;
  padding-left: 0.24rem;
  font-size: 0.24rem;
  color: rgba(0, 0, 0, 0.5);
  line-height: 0.34rem;
}
.refund_msg .refund_name_phone .refund_name {
  padding-right: 0.5rem;
}
.refund_msg .refund_address_new {
  padding-bottom: 0.24rem;
  display: flex;
  justify-content: flex-start;
  padding-left: 0.24rem;
  padding-right: 0.26rem;
  font-size: 0.24rem;
  color: rgba(0, 0, 0, 0.5);
  line-height: 0.34rem;
}
.refund_msg .refund_address_new .address_title {
  width: 1.2rem;
}
.refund_msg .refund_address_new .address_comtent {
  flex: 1;
}
.refund_msg_alert {
  font-weight: 400;
  color: #ff3c39;
  line-height: 0.28rem;
  font-size: 0.24rem;
  padding: 0.1rem 0 0.1rem 0.3rem;
}
.wu_number {
  position: absolute;
  left: 0.3rem;
  bottom: 0.2rem;
}
.wu_number p {
  font-weight: 400;
  color: rgba(0, 0, 0, 0.5);
  line-height: 0.34rem;
  max-width: 2.9rem;
  word-break: break-all;
  line-height: 0.34rem;
  font-size: 0.24rem;
}
</style>
